package gold.digger;

import java.util.ArrayList;
import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1600 {
    public long startExecuteTime = System.currentTimeMillis();


    class ThroneInheritance {

        String kingName;

        Map<String, List<String>> map = new HashMap<>();

        Set<String> deathSet = new HashSet<>();

        public ThroneInheritance(String kingName) {
            this.kingName = kingName;
            map.put(kingName, new LinkedList<>());
        }

        public void birth(String parentName, String childName) {
            map.get(parentName).add(childName);
            map.put(childName, new LinkedList<>());
        }

        public void death(String name) {
            deathSet.add(name);
        }

        public List<String> getInheritanceOrder() {
            List<String> result = new LinkedList<>();
            dfs(result, kingName);
            return result;
        }

        private void dfs(List<String> result, String name) {
            if (!deathSet.contains(name)) {
                result.add(name);
            }
            for (String subName : map.get(name)) {
                dfs(result, subName);
            }
        }
    }

    public void run() {
        ThroneInheritance solution = new ThroneInheritance("your King");
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC1600 an = new LC1600();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
